home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
414_01
/
prefix.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-28
|
53KB
|
1,322 lines
/***********************************************************************/
/* PREFIX.C - Prefix commands. */
/***********************************************************************/
/*
* THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
* Copyright (C) 1991-1993 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
*
* The Free Software Foundation, Inc.
* 675 Mass Ave,
* Cambridge, MA 02139 USA.
*
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling email: M.Hessling@gu.edu.au
* 36 David Road Phone: +61 7 849 7731
* Holland Park Fax: +61 7 875 5314
* QLD 4121
* Australia
*/
/*
$Header: C:\THE\RCS\prefix.c 1.4 1993/09/01 16:26:56 MH Interim MH $
*/
#include <stdio.h>
#include "the.h"
#include "proto.h"
/*-------------------------- declarations -----------------------------*/
#ifdef PROTO
static int parse_prefix_command(int,char *,char *);
static int invalidate_prefix(int);
static int prefix_makecurr(int,int,long);
static int prefix_add(int,int,long);
static int prefix_duplicate(int,int,long);
static int prefix_copy(int,int,long);
static int prefix_move(int,int,long);
static int prefix_delete(int,int,long);
static int prefix_shift_left(int,int,long);
static int prefix_shift_right(int,int,long);
static int prefix_block_duplicate(int,int,long);
static int prefix_block_copy(int,int,long);
static int prefix_block_move(int,int,long);
static int prefix_block_delete(int,int,long);
static int prefix_block_shift_left(int,int,long);
static int prefix_block_shift_right(int,int,long);
void clear_pending_prefix_command(int ,LINE *);
static int find_bottom_ppc(int,int);
static int find_target_ppc(int *);
static long calculate_target_line(void);
#if !defined(NOREXX)
static int try_rexx_prefix_macro(int);
#endif
static char *substr(char *, char *, int, int);
#else
static int parse_prefix_command();
static int invalidate_prefix();
static int prefix_makecurr();
static int prefix_add();
static int prefix_duplicate();
static int prefix_copy();
static int prefix_move();
static int prefix_delete();
static int prefix_shift_left();
static int prefix_shift_right();
static int prefix_block_duplicate();
static int prefix_block_copy();
static int prefix_block_move();
static int prefix_block_delete();
static int prefix_block_shift_left();
static int prefix_block_shift_right();
void clear_pending_prefix_command();
static int find_bottom_ppc();
static int find_target_ppc();
static long calculate_target_line();
static char *substr();
#endif
/*---------------------------------------------------------------------*/
/* The following two are to specify the first and last items in the */
/* linked list for prefix synonyms. */
/*---------------------------------------------------------------------*/
LINE *first_prefix_synonym=NULL;
LINE *last_prefix_synonym=NULL;
/*---------------------------------------------------------------------*/
#define PPC_NO_TARGET (-1)
#define PPC_NO_COMMAND (-2)
#define PPC_TARGET_PREVIOUS 0
#define PPC_TARGET_FOLLOWING 1
/* the above two defines correspond to the position in the pc[] array */
/* and should be changed if the position in pc[] array changes. */
#define NUMBER_PREFIX_COMMANDS 17
static PREFIX_COMMAND pc[NUMBER_PREFIX_COMMANDS] =
{
{(char *)"p",1,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,NULL},
{(char *)"f",1,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,NULL},
{(char *)"\"\"",2,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_block_duplicate},
{(char *)"cc",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,prefix_block_copy},
{(char *)"mm",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,prefix_block_move},
{(char *)"dd",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_delete},
{(char *)"<<",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_shift_left},
{(char *)">>",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_shift_right},
{(char *)"\"",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_duplicate},
{(char *)"c",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,prefix_copy},
{(char *)"m",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,prefix_move},
{(char *)"d",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_delete},
{(char *)"<",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_left},
{(char *)">",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_right},
{(char *)"i",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,prefix_add},
{(char *)"a",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,prefix_add},
{(char *)"/",1,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,prefix_makecurr},
};
char pending_prefix_command[PREFIX_WIDTH+1]="";
long prefix_current_line;
bool in_prefix_macro=FALSE; /* indicate if processing prefix macro */
/*-------------------------- external data ----------------------------*/
extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
/***********************************************************************/
#ifdef PROTO
int execute_prefix_commands(void)
#else
int execute_prefix_commands()
#endif
/***********************************************************************/
{
/*-------------------------- external data ----------------------------*/
extern char number_of_files;
/*--------------------------- local data ------------------------------*/
register int i;
int len,cmd_idx,rc,ppc_idx;
char cmd[PREFIX_WIDTH+1];
char mult[PREFIX_WIDTH+1];
int first_pending = (-1);
long long_mult=0L;
long start_line,number_lines,target_line;
int top_ppc,bot_ppc,target_ppc;
int number_prefix_commands;
/*--------------------------- processing ------------------------------*/
#ifdef TRACE
trace_function("prefix.c: execute_prefix_commands");
#endif
post_process_line(CURRENT_VIEW->focus_line);
/*---------------------------------------------------------------------*/
/* This variable is set here because post_process_line() actually sets */
/* CURRENT_VIEW->prefix_command_index. */
/*---------------------------------------------------------------------*/
number_prefix_commands = CURRENT_VIEW->prefix_command_index;
/*---------------------------------------------------------------------*/
/* For each pending prefix command for the current view, validate the */
/* command and parameters. */
/*---------------------------------------------------------------------*/
for (i=0;i<number_prefix_commands;i++)
{
/*---------------------------------------------------------------------*/
/* If a set point command, validate the name. */
/*---------------------------------------------------------------------*/
if (CURRENT_VIEW->ppc[i].ppc_command[0] == '.')
{
if (isalpha(CURRENT_VIEW->ppc[i].ppc_command[1]))
{
if (execute_set_point(CURRENT_VIEW->ppc[i].ppc_command,CURRENT_VIEW->ppc[i].ppc_line_number,TRUE) != RC_OK)
{
invalidate_prefix(i);
continue;
}
clear_pending_prefix_command(i,(LINE *)NULL);
continue;
}
else
{
invalidate_prefix(i);
continue;
}
}
/*---------------------------------------------------------------------*/
/* If an invalid